import { useSlots, reactive, ref, computed, onMounted, onUnmounted, openBlock, createElementBlock, isRef, createElementVNode, normalizeClass, unref, toDisplayString, createVNode, Transition, withCtx, withDirectives, Fragment, renderList, withModifiers, vShow, renderSlot, createTextVNode } from "vue";
var Select_vue_vue_type_style_index_0_scoped_true_lang = "";
var _export_sfc = (sfc, props) => {
  const target = sfc.__vccOpts || sfc;
  for (const [key, val] of props) {
    target[key] = val;
  }
  return target;
};
const _hoisted_1 = { class: "select_value" };
const _hoisted_2 = { class: "select_list" };
const _hoisted_3 = ["onClick"];
const _sfc_main$1 = {
  __name: "Select",
  props: {
    modelValue: String || Array,
    multiple: Boolean
  },
  emits: ["update:modelValue", "change"],
  setup(__props, { emit }) {
    const props = __props;
    const slots = useSlots();
    let options = reactive([]);
    let show = ref(false);
    let select = ref(null);
    let slot = slots.default();
    let data = [];
    if (slot.length > 1) {
      data = slot;
    } else {
      data = slot[0].children;
    }
    options = data.map((item) => {
      return {
        label: item.props.label,
        value: item.props.value
      };
    });
    const value = computed({
      get() {
        return props.modelValue;
      },
      set(value2) {
        emit("change", options.find((item) => {
          return item.value == value2;
        }));
        emit("update:modelValue", value2);
      }
    });
    const checkValue = computed(() => {
      var _a;
      return (_a = options.find((item) => {
        return item.value == value.value;
      })) == null ? void 0 : _a.label;
    });
    const checked = (item) => {
      value.value = item.value;
      if (props.multiple) {
        show.value = true;
      }
    };
    const Eevent = function(e) {
      new Promise((resolve, reject) => {
        let isClick = select.value.contains(e.target);
        resolve(isClick);
      }).then((data2) => {
        console.log(data2);
        if (!data2) {
          show.value = false;
        }
      });
    };
    onMounted(() => {
      document.addEventListener("click", Eevent);
    });
    onUnmounted(() => {
      document.removeEventListener("click", Eevent);
    });
    return (_ctx, _cache) => {
      return openBlock(), createElementBlock("div", {
        ref_key: "select",
        ref: select,
        class: "select_main",
        onClick: _cache[0] || (_cache[0] = ($event) => isRef(show) ? show.value = true : show = true),
        onClickCapture: _cache[1] || (_cache[1] = ($event) => isRef(show) ? show.value = false : show = false)
      }, [
        createElementVNode("div", {
          class: normalizeClass(["select_border", { active: unref(show) }])
        }, [
          createElementVNode("div", _hoisted_1, toDisplayString(unref(checkValue)), 1),
          createElementVNode("i", {
            class: normalizeClass(["samey-ui-icon sicon-arrow-down", { active: unref(show) }])
          }, null, 2),
          createVNode(Transition, { name: "transition-drop" }, {
            default: withCtx(() => [
              withDirectives(createElementVNode("div", _hoisted_2, [
                (openBlock(true), createElementBlock(Fragment, null, renderList(unref(options), (item, index2) => {
                  return openBlock(), createElementBlock("div", {
                    class: "option_value",
                    key: index2,
                    onClick: withModifiers(($event) => checked(item), ["stop"])
                  }, toDisplayString(item.label), 9, _hoisted_3);
                }), 128))
              ], 512), [
                [vShow, unref(show)]
              ])
            ]),
            _: 1
          })
        ], 2)
      ], 544);
    };
  }
};
var Select = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["__scopeId", "data-v-d7f6fb20"]]);
const __default__ = {
  inheritAttrs: true
};
const _sfc_main = /* @__PURE__ */ Object.assign(__default__, {
  __name: "Option",
  props: ["label", "value"],
  setup(__props) {
    return (_ctx, _cache) => {
      return renderSlot(_ctx.$slots, "default", {}, () => [
        createTextVNode(toDisplayString(__props.label), 1)
      ]);
    };
  }
});
var components = {
  "s_select": Select,
  "s_option": _sfc_main
};
const install$1 = (app) => {
  app.directive("rollBottom", (el, binding) => {
    console.log([el], binding);
    let timer = null;
    let isBottom = false;
    el.onscroll = function(e) {
      clearTimeout(timer);
      timer = setTimeout(function() {
        let bottom = el.dataset.bottom || 50;
        if (el.scrollHeight - (el.scrollTop + el.clientHeight) <= bottom) {
          if (!isBottom) {
            binding.value();
          }
          isBottom = true;
        } else {
          isBottom = false;
        }
      }, 300);
    };
  });
};
var util = { install: install$1 };
var index$1 = "";
const install = (App) => {
  for (let key in components) {
    App.component(key, components[key]);
  }
  App.use(util);
};
var index = { install };
export { index as default };
